<?
require_once('../includes/config.php');
if (DEBUG) {
	error_reporting(E_ALL); 
	ini_set('display_errors', '1');
}
$already_installed = false;
if (file_exists('../configuration.php') && !DEBUG) {
	$already_installed = true;
}

?>

<html>
	<head>
		<title>Installation af KomitCMS</title>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<link rel="stylesheet" type="text/css" href="../stylesheet/style.css" />
		<link rel="stylesheet" type="text/css" href="../stylesheet/install.css" />
		<script type="text/javascript">
			var DEBUG = false;
			var jSteps = [
			{name: 'Systemtjek', page: 'systemtest.php'},
			{name: 'Database', page: 'database.php'},
			{name: 'Konfiguration', page: 'configuration.php'},
			{name: 'Afslut', page: 'finish.php'}];
			var jStepCount = jSteps.length;
			var jCurrentStep = 0;
			var jPreviousStep = 0;
			
			function loadStep(jStep) {
				if (DEBUG) { alert('Load step: ' + jStep.name + ' ('+ jStep.page +')'); }
				document.getElementById('myFrame').src = jStep.page;
				setStepListItemClass(jSteps[jPreviousStep], '');
				setStepListItemClass(jSteps[jCurrentStep], 'current');
			}
			
			function nextStep() {
				jPreviousStep = jCurrentStep;
				if (jCurrentStep <= jStepCount - 1) {
					jCurrentStep += 1;
				}
				loadStep(jSteps[jCurrentStep]);
			}
			
			function getNextStep() {
				if (jCurrentStep <= jStepCount - 1) {
					return jSteps[jCurrentStep + 1];
				}
				return null;
			}
			
			function previousStep() {
				jPreviousStep = jCurrentStep;
				if (jCurrentStep > 0) {
					jCurrentStep -= 1;
				}
				loadStep(jSteps[jCurrentStep]);
			}
			
			function renderStepList(jEl) {
				var jList = document.createElement('ol');
				for (var i = 0; i < jSteps.length; i++) {
					var jStepEl = document.createElement('li');
					jStepEl.id = 'step_list_item_' + jSteps[i].name;
					jStepEl.innerHTML = jSteps[i].name;
					jList.appendChild(jStepEl); 
				}
				jEl.appendChild(jList);
			} 
			
			function setStepListItemClass(jStep, jClass) {
				var jStepId = 'step_list_item_' + jStep.name;
				var jStepEl = document.getElementById(jStepId);
				jStepEl.className = jClass;
			}
			
			function onLoad() {
				renderStepList(document.getElementById('steps'));
				loadStep(jSteps[jCurrentStep]);
			}
		</script>
	</head>
	
	<body onload="onLoad()">
		<? if ($already_installed) { ?>
			<div class="warning">
				<div class="warning_header"><b>KomitCMS</b> | Advarsel</div>
				<div class="warning_content">
					<b>HUSK AT FJERNE INSTALLATIONSMAPPEN!</b><br/><br/>
					Som en sikkerhedsfunktion i KomitCMS skal du fjerne installationsmappen før du begynder at bruge KomitCMS.
				</div>
			</div>
		<? } else { ?>
		<div id="install">
			<div id="header">
				<div><h1>Installation af KomitCMS</h1></div>
			</div>
			<div id="process">
				<h2>Trin</h2>
				<div id="steps"></div>
			</div>
			<div id="content">
				
				<iframe name="myFrame" id="myFrame" width="550px" height="500px" 
					style="border: 0; margin-top: 2px"></iframe>
			</div>
		</div>
		<? } ?>
	</body>
</html>